package com.kk.base.controller.home;

import com.kk.base.bean.CodeMsg;
import com.kk.base.bean.Result;
import com.kk.base.entity.admin.AgingQuery;
import com.kk.base.service.admin.AgingQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/home/aging")
public class HomeAgingQueryController {

    @Autowired
    private AgingQueryService agingQueryService;

    @RequestMapping(value = "/quotationTimeEnquiry",method = RequestMethod.POST)
    @ResponseBody
    public Result<ArrayList<Object>> quotationTimeEnquiry(AgingQuery agingQuery, BigDecimal weight){

        ArrayList<Object> objects = new ArrayList<>();

        List<AgingQuery> agingQueryList = agingQueryService.findAllByOriginAndDestination(agingQuery);

        if (agingQueryList.isEmpty()){
          return Result.error(CodeMsg.ADMIN_AGINGQUERY_SEL_ERROR);
        }

        objects.add(agingQueryList.get(0).getEta());
        BigDecimal bigDecimal = new BigDecimal(agingQueryList.get(0).getPricePerKilogram());
        BigDecimal result3 = bigDecimal.multiply(weight);
        objects.add(result3);

        return Result.success(objects);
    }


}
